<template>
  <div class="ma-content-block lg:flex justify-between p-4">
    <!-- CRUD 组件 -->
    <ma-crud :options="options" :columns="columns" ref="crudRef">
    </ma-crud>
  </div>
</template>
<script setup>
import {ref, reactive} from 'vue'
import backendUnit from '@/api/backend/unit.js'
import {Message} from '@arco-design/web-vue'
import tool from '@/utils/tool'
import * as common from '@/utils/common'

const crudRef = ref()


const options = reactive({
  id: 'backend_unit',
  rowSelection: {
    showCheckedAll: true
  },
  pk: 'id',
  operationColumn: true,
  operationColumnWidth: 160,
  formOption: {
    viewType: 'drawer',
    width: 600
  },
  api: backendUnit.getList,
  add: {
    show: true,
    api: backendUnit.save,
    auth: ['unit:save']
  },
  edit: {
    show: true,
    api: backendUnit.update,
    auth: ['unit:update']
  },
  delete: {
    show: true,
    api: backendUnit.deletes,
    auth: ['unit:delete']
  }
})

const columns = reactive([
  {
    title: "ID",
    dataIndex: "id",
    formType: "input",
    addDisplay: false,
    editDisplay: false
  },
  {
    title: "创建时间",
    dataIndex: "created_at",
    formType: "date",
    addDisplay: false,
    editDisplay: false,
    showTime: true
  },
  {
    title: "装置名称",
    dataIndex: "name",
    formType: "input"
  },
  {
    title: "装置版本",
    dataIndex: "version",
    formType: "input"
  },
  {
    title: "所属公司",
    dataIndex: "corp_id",
    commonRules: {required: true, message: "请选择公司"},
    formType: "select",
    multiple: false,
    dict: {
      remote: 'corp/remote',
      method: 'post',
      props: {label: 'name', value: 'id'},
      remoteOption: {
        select: ['id', 'name']
      },
      translation: true
    },
    search: true
  },
  {
    title: "所属项目",
    dataIndex: "project_id",
    commonRules: {required: true, message: "请选择项目"},
    formType: "select",
    multiple: false,
    dict: {
      remote: 'backend/project/remote',
      method: 'post',
      props: {label: 'name', value: 'id'},
      remoteOption: {
        select: ['id', 'name']
      },
      translation: true
    },
    search: true
  },
  {
    title: "关联设备",
    dataIndex: "device_id",
    commonRules: {required: true, message: "请选择设备"},
    formType: "select",
    multiple: true,
    dict: {
      remote: 'backend/device/remote',
      method: 'post',
      props: {label: 'device_name', value: 'id'},
      remoteOption: {
        select: ['id', 'device_name'],
        filter: {
          // bind_corp_id: ['=', 0]
        }
      },
      translation: true
    }
  }
])
</script>
<script> export default {name: 'unit'} </script>